#include "ecran.hpp"

Ecran::Ecran()
{
  const SDL_VideoInfo* videoInfo;

  SDL_Init(SDL_INIT_EVERYTHING);
  if(TTF_Init()==-1)
    {
      cout << "DU BRIN"<< endl;
    }
 
  /*
  videoInfo=SDL_GetVideoInfo();
  max_largeur=videoInfo->current_w;
  max_hauteur=videoInfo->current_h;
  */

  largeur_ecran=450;
  hauteur_ecran=650;

  //  SDL_EnableKeyRepeat(30,30);

  ecran=SDL_SetVideoMode(largeur_ecran,hauteur_ecran,30,SDL_HWSURFACE | SDL_DOUBLEBUF);

  SDL_WM_SetCaption("Formipachi",NULL);
}

Ecran::~Ecran()
{
  SDL_FreeSurface(ecran);
  TTF_Quit();
  SDL_Quit();
}

void Ecran::set_ecran(SDL_Surface * e)
{
  ecran=e;
}

void Ecran::set_hauteur(int h)
{
  hauteur_ecran=h;
}

void Ecran::set_largeur(int l)
{
  largeur_ecran=l;
}

SDL_Surface * Ecran::get_ecran()
{
  return ecran;
}

int Ecran::get_hauteur()
{
  return hauteur_ecran;
}

int Ecran::get_largeur()
{
  return largeur_ecran;
}

void Ecran::peindre(int x,int y,int l,int h,int r,int v,int b)
{
  SDL_Rect rectangle={x,y,l,h};
  SDL_FillRect(ecran, & rectangle, SDL_MapRGB(ecran->format,r,v,b));
}

void Ecran::afficher(int x,int y,SDL_Surface* source)
{
  SDL_Rect offset;
  offset.x=x;
  offset.y=y;

  SDL_BlitSurface(source,NULL,ecran,&offset);
}

void Ecran::bouton()
{
  SDL_Rect rectangle={50,50,50,50};
  SDL_FillRect(ecran, & rectangle, SDL_MapRGB(ecran->format,255,0,255));
}

void Ecran::flip()
{
  SDL_Flip(ecran);
}

SDL_Surface* load_image(string a)
{
  SDL_Surface* loadedImage = NULL;
  SDL_Surface* optimizedImage = NULL;

  loadedImage = IMG_Load(a.c_str());

  if( loadedImage != NULL )
 {
    optimizedImage = SDL_DisplayFormat( loadedImage );
    SDL_FreeSurface( loadedImage );
  }
  return optimizedImage;
}
